package net.crowdloud.server.DatabaseAccess.problem;

import java.util.ArrayList;
import java.util.List;

import net.crowdloud.shared.entities.Tags;

import com.google.appengine.api.datastore.Text;

public class ConvertProblemToDatabase {

	public static List<Problem> getDatabaseProblems(
			List<net.crowdloud.shared.entities.Problem> problems, String tags) {

		List<Problem> problemsDatabase = new ArrayList<Problem>();

		for (net.crowdloud.shared.entities.Problem problem : problems) {

			Problem problemDatabase = new Problem();
			problemsDatabase.add(getDatabaseProblem(problemDatabase, problem,
					tags));
		}

		return problemsDatabase;
	}

	public static Problem getDatabaseProblem(Problem problemDatabase,
			net.crowdloud.shared.entities.Problem problem, String tags) {

		problemDatabase.setDescription(new Text(problem.getDescription()));

		problemDatabase.setTags(new Text(Tags.getStaticTags(
				problem.getDescription(), tags)));

		return problemDatabase;
	}
}
